package org.elephas.webapp.component.themes;

import org.apache.wicket.Component;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import org.elephas.model.Blog;
import org.elephas.webapp.component.Theme;
import org.elephas.webapp.frontend.component.FooterPanel;
import org.elephas.webapp.frontend.component.HeaderPanel;
import org.elephas.webapp.frontend.component.PostPanel;
import org.elephas.webapp.frontend.component.RecentPostsPanel;
import org.elephas.webapp.frontend.page.blog.BlogBasePage;
import org.elephas.webapp.frontend.page.blog.BlogFrontPage;
import org.elephas.webapp.frontend.page.blog.BlogPostPage;
import org.elephas.webapp.model.DetachableBlogModel;
import org.elephas.webapp.model.DetachablePostModel;

/**
 * Created Apr 6, 2008
 * 
 * @author <a href="mailto:jlee@antwerkz.com">Justin Lee</a>
 */
public class DefaultTheme implements Theme {
	private static final long serialVersionUID = 1L;

	public String getName() {
		return "Default Theme";
	}

	public Component newHeader(String id, DetachableBlogModel blogModel,
			BlogBasePage page) {
		return new HeaderPanel(id, new PropertyModel(blogModel, "name"), page
				.getClass(), page.getPageParameters());
	}

	public Component newFrontPageContent(String id,
			DetachableBlogModel blogModel, BlogBasePage page) {
		return new RecentPostsPanel(id, blogModel, blogModel.getObject()
				.getConfiguration().getPostsOnFrontPage());
	}

	public Component newFooter(String id, DetachableBlogModel blogModel,
			BlogBasePage page) {
		return new FooterPanel(id, new StringResourceModel("footer.copyright",
				page, null));
	}

	public ResourceReference getCSS(BlogBasePage page) {
		return null;
	}

	public ResourceReference getJavascript(BlogBasePage page) {
		return null;
	}

	public Component newPostPageContent(String id, Blog blog, BlogPostPage page) {
		// TODO: use a better scheme like /year/month/day/postTitle instead of
		// uuid
		// int year = params.getInt("1");
		// int month = params.getInt("2");
		// int day = params.getInt("3");
		// String title = params.getString("4");
		String uuid = page.getPageParameters().getString(
				BlogFrontPage.POST_UUID);
		return new PostPanel(id, new DetachablePostModel(uuid));
	}
}